package com.iss.card.mapv2;

import android.app.Application;
import android.os.Process;
import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;

public class BDLocationClient extends Application {

	public LocationClient mLocationClient = null;
	public MyLocationListenner myListener = new MyLocationListenner();
	public static String TAG = "Location";

	@Override
	public void onCreate() {
		mLocationClient = new LocationClient(this);
		mLocationClient.registerLocationListener(myListener);
		super.onCreate();
		Log.d(TAG, "... Application onCreate... pid=" + Process.myPid());
	}

	public class MyLocationListenner implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation newLocation) {
			if (newLocation == null)
				return;
			MyLocationManager.instance()
					.setCurrentLocationPosition(newLocation);
			StringBuffer sb = new StringBuffer(256);
			sb.append("time : ");
			sb.append(newLocation.getTime());
			sb.append("\nloc type : ");
			sb.append(newLocation.getLocType());
			sb.append("\nlatitude : ");
			sb.append(newLocation.getLatitude());
			sb.append("\nlontitude : ");
			sb.append(newLocation.getLongitude());
			sb.append("\nradius : ");
			sb.append(newLocation.getRadius());
			if (newLocation.getLocType() == BDLocation.TypeGpsLocation) {
				sb.append("\nspeed : ");
				sb.append(newLocation.getSpeed());
				sb.append("\nsatellite : ");
				sb.append(newLocation.getSatelliteNumber());
			} else if (newLocation.getLocType() == BDLocation.TypeNetWorkLocation) {
				sb.append("\naddr : ");
				sb.append(newLocation.getAddrStr());
			}
			sb.append("\nsdk version : ");
			sb.append(mLocationClient.getVersion());
			sb.append("\nisCellChangeFlag : ");
			sb.append(newLocation.isCellChangeFlag());
			Log.i(TAG, sb.toString());
		}

		public void onReceivePoi(BDLocation poiLocation) {
			if (poiLocation == null) {
				return;
			}
			StringBuffer sb = new StringBuffer(256);
			sb.append("Poi time : ");
			sb.append(poiLocation.getTime());
			sb.append("\nerror code : ");
			sb.append(poiLocation.getLocType());
			sb.append("\nlatitude : ");
			sb.append(poiLocation.getLatitude());
			sb.append("\nlontitude : ");
			sb.append(poiLocation.getLongitude());
			sb.append("\nradius : ");
			sb.append(poiLocation.getRadius());
			if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation) {
				sb.append("\naddr : ");
				sb.append(poiLocation.getAddrStr());
			}
			if (poiLocation.hasPoi()) {
				sb.append("\nPoi:");
				sb.append(poiLocation.getPoi());
			} else {
				sb.append("noPoi information");
			}
		}
	}
}